package training_camp.day2.leetcode209;

class Solution {
    public int minSubArrayLen(int target, int[] nums) {
        int left, right;
        left = 0;
        right = 0;
        int window = 0;
        int ans = Integer.MAX_VALUE;
        while (right < nums.length) {
            window += nums[right];
            while(window>=target){
                ans = Math.min(ans , right - left+1);
                window -= nums[left];
                left++;
            }
            right++;
        }
        return ans == Integer.MAX_VALUE ? 0 : ans;
    }
}